////
////  HDClassTableView.swift
////  Excited
////
////  Created by X140Yu on 6/15/16.
////  Copyright (c) 2016 X140Yu. All rights reserved.
////
//
//import UIKit
//import RxCocoa
//import RxSwift
//
//class HHClassTableView: UIView
//{
//    var headerView = UIView()
//    var scrollView = UIScrollView()
//    let disposeBag = DisposeBag()
//    var colorDictionary = Dictionary<String, UIColor>()
//    var currentColorIndex = 0
//
//
//    func setClass(classArray: [HDClass], week: Int) {
//        
//        // 先移除所有显示的课程
//        for btns in self.scrollView.subviews {
//            if let btn = btns as? HHClassButton {
//                btn.removeFromSuperview()
//            }
//        }
//   
//        // 说明刷新不到课程
//        if classArray.count == 0 {
//            return
//        }
//       
//        for classInfo in classArray {
//            
//            if classInfo.inCurrentWeek(week) == false {
//                continue
//            }
//            
//            let xIndex = CGFloat(Int(classInfo.dayOfWeek!)!)
//            let yIndexStart = CGFloat(Int(classInfo.startSection!)!)
//            let numberOfClass = Int(classInfo.endSection!)! - Int(classInfo.startSection!)! + 1
//           
//            let button = HHClassButton(frame: CGRect(x: Constants.LeftLabelWidth + (xIndex - 1) * Constants.ClassCellWidth, y: (yIndexStart - 1) * Constants.ClassCellHeight, width: Constants.ClassCellWidth, height: Constants.ClassCellHeight * CGFloat(numberOfClass)))
//            button.classInfo = classInfo
//            button.backgroundColor = randomButtonColor(classInfo.cname!)
//            button.classNameLabel.text = "\(classInfo.cname!)@\(classInfo.classroom!)"
//            button.rx_tap.subscribeNext({ () in
//                let classInfo = button.classInfo!
//                let alert = UIAlertView(title: nil, message: classInfo.detailInfo(), delegate: nil, cancelButtonTitle: "OK")
//                alert.show()
//            }).addDisposableTo(disposeBag)
//            scrollView.addSubview(button)
//        }
//    }
//    
//    struct Constants {
//        static let BorderColor = UIColor.whiteColor()
//        static let LabelTitleColor = UIColor(red: 134.0/255, green: 134.0/255, blue: 134.0/255, alpha: 1)
//        /// Grey
//        static let BackgroundColor = UIColor(red: 220.0/255, green: 220.0/255, blue: 220.0/255, alpha: 1)
//        
//        // Cell
//        static let ClassCellWidth: CGFloat = (Constants.ViewWidth - Constants.LeftLabelWidth) / 7
////        static let ClassCellHeight: CGFloat = 120
//        static let ClassCellHeight: CGFloat = (Constants.ViewHeight + 90) * 0.2 / 2
//        
//        // 顶部标题 label
//        static let HeaderLabelWidth: CGFloat = Constants.ClassCellWidth
//        static let HeaderLabelHeight: CGFloat = 30
//        
//        /// Scrollview 左侧的标题 label 的宽度
//        static let LeftLabelWidth: CGFloat = 30
//        /// Scrollview 左侧的标题 label 的高度
//        static let LeftLabelHeight: CGFloat = Constants.ClassCellHeight
//        
//        /// HeaderView 的高度
//        static let HeaderViewHeight: CGFloat = Constants.HeaderLabelHeight
//        /// HeaderView 的宽度
//        static let HeaderViewWidth: CGFloat = Constants.ViewWidth
//        
//        /// 整个 View 的宽度
//        static let ViewWidth: CGFloat = UIScreen.mainScreen().bounds.width
//        /// 整个 View 的高度
//        static let ViewHeight: CGFloat = UIScreen.mainScreen().bounds.height - 64 - 49
//        
//        /// Scrollview 的高度
//        static let ScrollViewHeight: CGFloat = Constants.ViewHeight - Constants.HeaderViewHeight
//        /// Scrollview 的宽度
//        static let ScrollViewWidth: CGFloat = Constants.ViewWidth
//        
//        /// 左上角的方块的高度
//        static let CornerHeight: CGFloat = Constants.HeaderLabelHeight
//        /// 左上角的方块的宽度
//        static let CornerWidth: CGFloat = Constants.LeftLabelWidth
//        
//    }
//    
//    func addLineView() {
//        // -------
//        for i in 0...10 {
//            let lineView = UIView()
//            lineView.backgroundColor = Constants.BorderColor
//            scrollView.addSubview(lineView)
//            lineView.snp_makeConstraints(closure: { (make) in
//                make.top.equalTo(CGFloat(i) * Constants.ClassCellHeight)
//                make.height.equalTo(1)
//                make.width.equalTo(Constants.ViewWidth)
//            })
//            
//        }
//        
//        // | | | |
//        for i in 0...7 {
//            let lineView = UIView()
//            lineView.backgroundColor = Constants.BorderColor
//            scrollView.addSubview(lineView)
//            lineView.snp_makeConstraints(closure: { (make) in
//                make.left.equalTo(CGFloat(i) * Constants.ClassCellWidth + Constants.LeftLabelWidth)
//                make.top.equalTo(0)
//                make.height.equalTo(CGFloat(10) * Constants.LeftLabelHeight)
//                make.width.equalTo(1)
//            })
//        }
//        
//        // most left |
//        let leftLineView = UIView()
//        leftLineView.backgroundColor = Constants.BorderColor
//        scrollView.addSubview(leftLineView)
//        leftLineView.snp_makeConstraints { (make) in
//            make.left.equalTo(0)
//            make.top.equalTo(0)
//            make.height.equalTo(CGFloat(10) * Constants.LeftLabelHeight)
//            make.width.equalTo(1)
//        }
//        
//        // most right | 
//        let lineView = UIView()
//        lineView.backgroundColor = Constants.BorderColor
//        scrollView.addSubview(lineView)
//        lineView.snp_makeConstraints { (make) in
//            make.left.equalTo(UIScreen.mainScreen().bounds.width - 1)
//            make.top.equalTo(0)
//            make.height.equalTo(CGFloat(10) * Constants.LeftLabelHeight)
//            make.width.equalTo(1)
//        }
//
//    }
//    
//    override init(frame: CGRect) {
//        super.init(frame: frame)
//        
//        addSubview(headerView)
//        
//        scrollView.backgroundColor = Constants.BackgroundColor
//        addSubview(scrollView)
//        
//        addLineView()
//
//        updateLayerFrames()
//    }
//
//    required init?(coder aDecoder: NSCoder) {
//        fatalError("init(coder:) has not been implemented")
//    }
//    
//    func updateLayerFrames() {
//        
//        headerView.frame = CGRect(x: 0, y: 0, width: UIScreen.mainScreen().bounds.width, height: 30)
//        scrollView.frame = CGRect(x: 0, y: 30, width: headerView.bounds.width, height: UIScreen.mainScreen().bounds.height - 64 - 49 - 64)
//        scrollView.contentSize = CGSize(width: Constants.ViewWidth, height: CGFloat(10) * Constants.LeftLabelHeight)
//        scrollView.showsVerticalScrollIndicator = true
//        
//        let cornerLabel = UILabel(frame: CGRect(x: 0, y: 0, width: Constants.CornerWidth, height: Constants.CornerHeight))
//        cornerLabel.backgroundColor = Constants.BackgroundColor
//        cornerLabel.layer.borderWidth = 1
//        cornerLabel.layer.borderColor = Constants.BorderColor.CGColor
//        headerView.addSubview(cornerLabel)
//        
//        // 没课的时候显示的label
//   
//        
//        
//        // 顶部的 label
//        let headArr = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
//        for i in 0...6 {
//            let label = UILabel(frame: CGRect(x: Constants.CornerWidth + CGFloat(i) * Constants.HeaderLabelWidth, y: 0, width: Constants.HeaderLabelWidth, height: Constants.HeaderLabelHeight))
//            label.backgroundColor = Constants.BackgroundColor
//            label.layer.borderWidth = 1
//            label.layer.borderColor = Constants.BorderColor.CGColor
//            label.text = headArr[i]
//            label.textColor = Constants.LabelTitleColor
//            label.font = UIFont.boldSystemFontOfSize(14)
//            label.textAlignment = NSTextAlignment.Center
//            label.alpha = 1
//            headerView.addSubview(label)
//        }
//
//        // 侧面的label
//        for i in 1...10 {
//            let label = UILabel(frame: CGRect(x: 0, y: CGFloat(i - 1) * Constants.LeftLabelHeight, width: Constants.LeftLabelWidth, height: Constants.LeftLabelHeight))
//            label.backgroundColor = UIColor.clearColor()
//            label.text = "\(i)"
//            label.font = UIFont.boldSystemFontOfSize(16)
//            label.textColor = Constants.LabelTitleColor
//            label.textAlignment = NSTextAlignment.Center
//            label.alpha = 1
//            scrollView.addSubview(label)
//        }
//        
//    }
//}
//
//
//extension HHClassTableView {
//    func randomButtonColor(className: String) -> UIColor {
//        
//        let color = UIColor.color(245, myGreen: 97, myBlue: 144)
//        let color1 = UIColor.color(61, myGreen: 209, myBlue: 223)
//        let color2 = UIColor.color(247, myGreen: 106, myBlue: 100)
//        let color3 = UIColor.color(49, myGreen: 188, myBlue: 85)
//        let color4 = UIColor.color(144, myGreen: 169, myBlue: 248)
//        let color5 = UIColor.brownColor()
//        let color6 = UIColor.redColor()
//        let color7 = UIColor.darkGrayColor()
//
//
//        let arr = [color, color1, color2, color3, color4, color5, color6, color7]
//        if let color = colorDictionary[className] {
//            return color
//        } else {
//            colorDictionary[className] = arr[currentColorIndex % arr.count]
//            let colorRet = arr[currentColorIndex % arr.count]
//            currentColorIndex += 1
//            return colorRet
//        }
//    }
//}
//
//extension UIColor {
//    class func color(myRed: CGFloat, myGreen: CGFloat, myBlue: CGFloat) -> UIColor {
//        return UIColor(red: myRed/255.0, green: myGreen/255.0, blue: myBlue/255.0, alpha: 1)
//    }
//}
